// 引入web3.js库
const { default: Web3 } = require("web3")
let Web3 = require("web3")

// 创建web3.js实例，地址对应的是Gannache以太坊测试网
var web3 = new Web3(new Web3.providers.HttpProvider("HTTP://127.0.0.1:7545"))
// 获取ABI接口文件并转为json格式
var contractAbi = JSON.parse('[{"constant":true,"inputs":[],"name":"getNum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_num","type":"uint256"}],"name":"setNum","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]')
// 获取合约地址
var contractAddress = "0x1787d6c8e25aac79771da4001afc6f4eba89034cc14305af8ed55c81da794db0"
// 创建合约对象
var simpleContract = new web3.eth.Contract(contractAbi,contractAddress)
// 打印合约对象地址
console.log(simpleContract.options.address);